﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ESOL.Common.Entity;
using ESOL.Business.Prod;

namespace ESOL.Services
{
   public partial class ProdService : IProdService
    {


       public List<ProdWoTaskDetailEntity> ScheduleWoList(string[] planOrderList, List<ScheduleInput> input, string SchType)
       {
           List<ProdWoTaskDetailEntity> scheduleOutput = new List<ProdWoTaskDetailEntity>();
           //计划优先级已按照list顺序排好
           foreach (string planOrder in planOrderList)
           {
               List<ProdWoTaskDetailEntity> schedule = new List<ProdWoTaskDetailEntity>();
              // schedule = ScheduleWo(planOrder, input, SchType);
               //if (schedule != null) scheduleOutput.AddRange(schedule);
           }
           return null;
       }


       public string ScheduleWo(ProdWoEntity wo, List<ScheduleInput> input, string SchType, List<string> waitingWoList)
       {

           string  output = "";
           try
           {
               
               PPSchedule sch = new PPSchedule(wo.PoId);
               string result= sch.ScheduleWo(input, "", wo, waitingWoList);
               return result;
           }
           catch (Exception ex)
           {
               return ex.Message;
           }
           
       }


       public DataSet GetScheduleDetail(string woNo, string workgroup, string technicId)
       {
           return ProdWoTaskBs.GetScheduleDetailDsByCondition(woNo, workgroup, technicId);
       }

       public DataSet GetProdWoTask(string woNo)
       {
           return ProdWoTaskBs.GetProdWoTaskDsByWo(woNo);
       }

       public DataSet GetProdWoTaskDsByPo(string poId)
       {
           return ProdWoTaskBs.GetProdWoTaskDsByPo(poId);
       }


       public DataSet GetProdWoTaskDailyByWorkGroup(DateTime date)
       {
           return ProdWoTaskBs.GetProdWoTaskDailyByWorkGroup(date);
       }


       public DataSet GetAllWorkGroupFromWoTask(DateTime date)
       {
           return ProdWoTaskBs.GetAllWorkGroupFromWoTask(date);
       }

       //取指定计划工单的优先级
       public List<ProdWoEntity> GetScheduleWoPriority(string planOrderId)
       {
           PPSchedule pp = new PPSchedule(planOrderId);
           return pp.GetScheduleWoPriority();
       }


       public DataSet ScheduleWoList(List<ProdWoEntity> woList , List<ScheduleInput> input, string SchType)
       {

           DataSet output = null;
           string poId = woList[0].PoId;
           PPSchedule sch = new PPSchedule(poId);
           sch.ScheduleWoList(woList,input, "");
           output = ProdWoTaskBs.GetProdWoTaskDsByPo(poId);
           return output;
       }

       public List<ScheduleInput> GetScheduleWoInputFormat(string woNo)
       {
           List<ScheduleInput> inputList=new List<ScheduleInput>();
           DataSet ds = ProdWoBs.GetScheduleWoInputFormat(woNo);
           if (ds != null && ds.Tables.Count > 0)
           {
               foreach (DataRow row in ds.Tables[0].Rows)
               {
                   ScheduleInput input = new ScheduleInput();
                   input.WoNo = row["WO_NO"].ToString();
                 
                   input.Sequence =Convert.ToInt32( row["SEQUENCE"]);
                   input.TechnicId = row["TECHNIC_ID"].ToString();
                   input.TechnicName = row["Technic_Name"].ToString();
                   if(!string.IsNullOrEmpty(row["PLAN_START_DATE"].ToString()))
                   input.StartDate =Convert.ToDateTime( row["PLAN_START_DATE"]);
                   
                   input.WorkGroupId = row["workGroupId"].ToString();
                   input.WorkGroupName = row["WorkGroup_Name"].ToString();
                   input.WoNo = row["WO_NO"].ToString();
                   input.PlanOrder = row["PO_ID"].ToString();
                   inputList.Add(input);
               }
           }
           return inputList;

       }


       public string UpdateWoScheduleDate(List<string> woList)
       {
           try
           {
               
             bool re=  ProdWoBs.UpdateWoScheduleDate(woList);
             if (re)
                 return "";
             else
                 return "UpdateWoScheduleDate： 保存失败！";
           }
           catch (Exception ex)
           {
               return ex.Message;
           }

       }


       //保存工单任务排程
       public string SaveWoTask(List<string> woList)
       {
           try
           {
               return   PPSchedule.SaveWoTask(woList);
           }
           catch (Exception ex)
           {
               return ex.Message;
           }
       }
    }

 


}
